﻿<%@ Page Language="C#" MasterPageFile="~/Layout.Master" AutoEventWireup="true" CodeBehind="editReservation.aspx.cs" Inherits="PT.pages.editReservation" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    </asp:Content>
<asp:Content ID="cpContent" ContentPlaceHolderID="cpContent" runat="server">
    <asp:DetailsView ID="DetailsView2" runat="server" AutoGenerateRows="False" 
        BorderStyle="None" CssClass="grid" DataKeyNames="id" 
        DataSourceID="SqlDataSource1" Height="50px" Width="125px">
        <FieldHeaderStyle ForeColor="#FF9900" />
        <Fields>
            <asp:BoundField DataField="name" HeaderText="Nazwa" SortExpression="name" />
            <asp:BoundField DataField="size" HeaderText="Rozmiar" SortExpression="size" 
                DataFormatString="{0} os./pokój" />
            <asp:BoundField DataField="cost" HeaderText="Cena za dobę" 
                SortExpression="cost" DataFormatString="{0} zł" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:HotelConnectionString1 %>" 
        InsertCommand="INSERT INTO [Reservation] ([startDate], [endDate], [bookerName], [telephone]) VALUES (@startDate, @endDate, @bookerName, @telephone)" 
        OldValuesParameterFormatString="original_{0}" 
        
        SelectCommand="SELECT res.*, roo.name, roo.size, roo.cost FROM Reservation res  JOIN Rooms roo ON res.id=@reservation_id AND res.room_id = roo.id
" 
        ConflictDetection="CompareAllValues" 
        DeleteCommand="DELETE FROM [Reservation] WHERE [id] = @original_id AND [startDate] = @original_startDate AND [endDate] = @original_endDate AND [bookerName] = @original_bookerName AND (([telephone] = @original_telephone) OR ([telephone] IS NULL AND @original_telephone IS NULL))" 
        
        UpdateCommand="UPDATE [Reservation] SET [startDate] = @startDate, [endDate] = @endDate, [bookerName] = @bookerName, [telephone] = @telephone WHERE [id] = @reservation_id">
        <SelectParameters>
            <asp:QueryStringParameter Name="reservation_id" QueryStringField="id" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="original_id" Type="Int32" />
            <asp:Parameter DbType="Date" Name="original_startDate" />
            <asp:Parameter DbType="Date" Name="original_endDate" />
            <asp:Parameter Name="original_bookerName" Type="String" />
            <asp:Parameter Name="original_telephone" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="startDate" />
            <asp:Parameter Name="endDate" />
            <asp:Parameter Name="bookerName" />
            <asp:Parameter Name="telephone" />
            <asp:QueryStringParameter Name="reservation_id" QueryStringField="id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="startDate" />
            <asp:Parameter Name="endDate" />
            <asp:Parameter Name="bookerName"/>
            <asp:Parameter Name="telephone"/>
        </InsertParameters>
    </asp:SqlDataSource>
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" BorderStyle="None" 
        CssClass="grid" DataKeyNames="id" DataSourceID="SqlDataSource1" 
        DefaultMode="Edit" Height="50px" Width="125px" 
        onitemupdated="DetailsView1_ItemUpdated">
        <Fields>
            <asp:BoundField DataField="startDate" HeaderText="Początek" 
                SortExpression="startDate" />
            <asp:BoundField DataField="endDate" HeaderText="Koniec" 
                SortExpression="endDate" />
            <asp:BoundField DataField="bookerName" HeaderText="Rezerwujący" 
                SortExpression="bookerName" />
            <asp:BoundField DataField="telephone" HeaderText="Tel." 
                SortExpression="telephone" />
            <asp:CommandField ShowCancelButton="False" ShowEditButton="True" />
        </Fields>
        <InsertRowStyle BorderStyle="None" />
        <EditRowStyle BorderStyle="None" />
    </asp:DetailsView>
</asp:Content>
